package com.chat.common.model;

import java.util.HashMap;

/**
 * @author xiaoqiang
 */
public class BaseResponse extends HashMap<String,Object> {

    public BaseResponse message(String message){
        this.put("code",200);
        this.put("message", message);
        return this;
    }

    public BaseResponse unLogin(){
        this.put("code",500);
        this.put("message","用户未登陆");
        return this;
    }

    public BaseResponse error(String message){
        this.put("code",400);
        this.put("message",message);
        return this;
    }
    public BaseResponse authError(String message){
        this.put("code",401);
        this.put("message",message);
        return this;
    }

    public BaseResponse data(Object data){
        this.put("code",200);
        this.put("data", data);
        return this;
    }


    public BaseResponse(Object data){
        this.put("code",200);
        this.put("data", data);
    }

    public BaseResponse(Boolean flag){
        if(flag){
            this.put("code",200);
            this.put("message","success");
        }else{
            this.put("code",400);
            this.put("message","失败");
        }
    }

    public BaseResponse(boolean flag){
        if(flag){
            this.put("code",200);
            this.put("message","success");
        }else{
            this.put("code",400);
            this.put("message","失败");
        }
    }

    public BaseResponse(){
        this.put("code",200);
        this.put("message","success");
    }

    public BaseResponse success(){
        this.put("code",200);
        this.put("message","success");
        return this;
    }


    public BaseResponse put(String key, Object value){
        super.put(key,value);
        return this;
    }

    public String getMessage() {
        return String.valueOf(get("message"));
    }

    public Object getData(){
        return get("data");
    }

}
